
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.ResultSet"%>

<%@page import="java.sql.*"%>


<%@page import="com.xhd.Dao.SalerDaoImpl"%>
<%@page import="com.xhd.Dao.SalerDao"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.xhd.vo.Tuijian"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<link href="css/Tuijian.css" rel="stylesheet" type="text/css">
<script>
window.onload=function(){
	var btn_1=document.getElementById("btn_1");
	var btn_2=document.getElementById("btn_2");
	var close=document.getElementsByClassName("close");
	var close_1=document.getElementsByClassName("close_1");
	var dialog=document.getElementsByClassName("dialog");
	var form_1=document.getElementsByClassName("form_1");
	btn_1.addEventListener('click',function(){
		form_1[0].className="form_1 open";	
	})
	close[0].addEventListener('click',function(){
		form_1[0].className="form_1";
	})
	btn_2.addEventListener('click',function(){
		dialog[0].style.visibility='visible';
	})
	close_1[0].addEventListener('click',function(){
		dialog[0].style.visibility='hidden';
	})	
}

</script>
</head>
<style>
table{
    width: 100%;
    border-collapse: collapse;
}

table caption{
    font-size: 2em;
    font-weight: bold;
    margin: 1em 0;
}

th,td{
    border: 1px solid #999;
    text-align: center;
    padding: 20px 0;
}

table thead tr{
    background-color: #008c8c;
    color: #fff;
}

table tbody tr:nth-child(odd){
    background-color: #eee;
}

table tbody tr:hover{
    background-color: #ccc;
}

table tbody tr td:first-child{
    color: #f40;
}

table tfoot tr td{
    text-align: right;
    padding-right: 20px;
}

 </style>
<body>
<div class="main">
<button id="btn_1">点击输入推荐水果</button><br><br><br>



<div class="form_1">
<form action="ChoujiangServlet?method=addTuijian" method="post">
	<div class="input_1"><div class="login_logo">今日推荐水果</div><div class="close">X</div></div>
	<div class="input_1">水果名：<input type="text" name="TJfruit" ></div>
	<div class="select-box">推荐最好食用月份：
                <select name="yuefen" >
     <option value="1月" name="yiyue">1月</option>
     <option value="2月" name="eryue">2月</option>
     <option value="3月" name="sanyue">3月</option>
     <option value="4月" name="siyue">4月</option>
     <option value="5月" name="wuyue">5月</option>
     <option value="6月" name="liuyue">6月</option>
     <option value="7月" name="qiyue">7月</option>
     <option value="8月" name="bayue">8月</option>
     <option value="9月" name="jiuyue">9月</option>
     <option value="10月" name="shiyue">10月</option>
     <option value="11月" name="shiyiyue">11月</option>
     <option value="12月" name="shieryue">12月</option>
    </select>
            </div>
            <div>推荐理由：<input  type="text" name="tjly" ></div>
	<div class="input_1"><input class="submit_1" type="submit" value="确&nbsp;定"></div>		
</div>	

<% request.setCharacterEncoding("utf-8");
	String mess=request.getParameter("mess");
	mess=mess.trim();
	String submit = request.getParameter("submit");
	if(mess.length() == 0){
		response.sendRedirect("Tuijian.jsp");
		return;
	}
	Connection con=null;
	Statement sql;
	ResultSet rs;
	PreparedStatement pre=null;
	try{
		Class.forName("com.mysql.cj.jdbc.Driver");
	}catch(Exception e){
		out.print("<h1>"+e);
	}
	String URL="jdbc:mysql://localhost:3306/fruit";
	String USER="root";
	String PWD="root";
	out.print("<table border=1 ");
	out.print("<tr>");
	out.print("<th id = tom >"+"水果名");
	out.print("<th id = tom >"+"月份");
	out.print("<th id = tom >"+"推荐理由");
	out.print("<th id = tom >"+"删除");
	
	out.print("</tr>");
	String delSQL="delete from tuijian where TJfruit=?";
	try{
		con =DriverManager.getConnection(URL,USER,PWD);
		sql=con.createStatement();
		String SQL=null;
 
		if(submit.contains("水果名")){
			SQL="select * from tuijian where TJfruit like '%" + mess + "%'";
		}
		else if(submit.contains("月份")){
			SQL="select * from tuijian where yuefen like '%" + mess + "%'";
		}
		rs=sql.executeQuery(SQL);
		while(rs.next()){
			pre = con.prepareStatement(delSQL);
			out.print("<tr>");
			out.print("<th id = tom >"+rs.getString(1)+"</td>");
			out.print("<th id = tom >"+rs.getString(2)+"</td>");
			out.print("<th id = tom >"+rs.getString(3)+"</td>");
			out.print("<th id = tom >"+"返回上一页操作"+"</td>");
			
			out.print("</tr>");
		}
		out.print("</table>");
		con.close();
	}catch(SQLException e){
		out.print("<h1>"+e);
	}
%>


<a href="Tuijian.jsp">返回推荐页</a>
</div>	
</form>
</body>

</html>